def sms(n: int, list1: list) -> any:
    dict_1 = {}
    index = 0
    for value in list1:
        if value <= n:
            if value in dict_1:
                dict_1[value] = dict_1[value] + 1
                if (dict_1[value]) > index:
                    index = dict_1[value] 
            else:
                dict_1[value] = 1
                index = dict_1[value]
    list_max = []
    for key in dict_1:
        value = dict_1[key]
        if value == index:
            list_max.append(key)
    list_max.sort()
    if len(list_max) == 1:
        return list_max[0]
    return list_max

assert sms(3, [1, 2, 2, 3, 2, 3]) == 2
assert sms(2, [2,1,2,1]) == [1,2]
assert sms(3, [4,3,4]) == 3
assert sms(4, [3,5,1,2,3,3,2,5,1,1]) == [1,3]